package com.ruoyi.sale.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.sale.domain.SysSale;
import com.ruoyi.sale.service.ISysSaleService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 销售表Controller
 * 
 * @author sj
 * @date 2022-06-07
 */
@RestController
@RequestMapping("/sale/sale")
public class SysSaleController extends BaseController
{
    @Autowired
    private ISysSaleService sysSaleService;

    /**
     * 查询销售表列表
     */
    @PreAuthorize("@ss.hasPermi('sale:sale:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysSale sysSale)
    {
        startPage();
        List<SysSale> list = sysSaleService.selectSysSaleList(sysSale);
        return getDataTable(list);
    }

    /**
     * 导出销售表列表
     */
    @PreAuthorize("@ss.hasPermi('sale:sale:export')")
    @Log(title = "销售表", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysSale sysSale)
    {
        List<SysSale> list = sysSaleService.selectSysSaleList(sysSale);
        ExcelUtil<SysSale> util = new ExcelUtil<SysSale>(SysSale.class);
        util.exportExcel(response, list, "销售表数据");
    }

    /**
     * 获取销售表详细信息
     */
    @PreAuthorize("@ss.hasPermi('sale:sale:query')")
    @GetMapping(value = "/{saleId}")
    public AjaxResult getInfo(@PathVariable("saleId") Long saleId)
    {
        return AjaxResult.success(sysSaleService.selectSysSaleBySaleId(saleId));
    }

    /**
     * 新增销售表
     */
    @PreAuthorize("@ss.hasPermi('sale:sale:add')")
    @Log(title = "销售表", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysSale sysSale)
    {
        return toAjax(sysSaleService.insertSysSale(sysSale));
    }

    /**
     * 修改销售表
     */
    @PreAuthorize("@ss.hasPermi('sale:sale:edit')")
    @Log(title = "销售表", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysSale sysSale)
    {
        return toAjax(sysSaleService.updateSysSale(sysSale));
    }

    /**
     * 删除销售表
     */
    @PreAuthorize("@ss.hasPermi('sale:sale:remove')")
    @Log(title = "销售表", businessType = BusinessType.DELETE)
	@DeleteMapping("/{saleIds}")
    public AjaxResult remove(@PathVariable Long[] saleIds)
    {
        return toAjax(sysSaleService.deleteSysSaleBySaleIds(saleIds));
    }
}
